package presentation;
import java.io.IOException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;

import model.Catalog;
import model.Event;
import model.Hall1;
import model.Hall2;
import model.Hall3;

public class Driver {
	public static void testSetup(){
		GregorianCalendar date = new GregorianCalendar(2012, Calendar.APRIL, 1);
		Event e1 = new Event("event1" ,date,0, 10, Hall1.getInstance());
		Event e2 = new Event("event2" ,date,0, 10, Hall1.getInstance());
		Event e3 = new Event("event3" ,date,0, 10, Hall2.getInstance());
		Event e4 = new Event("event4" ,date,0, 10, Hall3.getInstance());
		Hall1.getInstance().add(e1);
		Hall1.getInstance().add(e2);
		Hall2.getInstance().add(e3);
		Hall3.getInstance().add(e4);
		
		//System.out.println(e4.toFile());
		//e1.save();
		//Event.load(1);
		//Event.loadAll();
		
	}
	public static void mainMenu(){
		Scanner kb=new Scanner(System.in);
		int input;
		System.out.println("Welcome to the FEBS");
		
		while(true){
			System.out.println("Press 1 to view all events.");
			System.out.println("Press 2 to create a booking");
			System.out.println("or press 0 to exit");
			input = kb.nextInt();
			switch(input){
			case 0: System.exit(0);
					break;
			case 1: Catalog.getInstance().viewAllEvents();
					break;
			case 2: bookingMenu();
					break;
			default:
					break;
			}
		}
	}
	
	public static void bookingMenu(){
		Scanner kb=new Scanner(System.in);
		int input;
		
		while(true){
			System.out.println("Enter the ID of the event you wish to book for");
			System.out.println("or press 0 to go exit");
			input = kb.nextInt();
			if(input == 0){
				break;
			}
			else{
				Event eventSearched = Catalog.getInstance().finfEventbyID(input);
				if(eventSearched == null){
					break;
				}
				else{
					//System.out.println(eventSearched);
					eventBookingMenu(eventSearched);				}
			}
		}
	}
	public static void eventBookingMenu(Event event){
		Scanner kb=new Scanner(System.in);
		int input;
		
		System.out.println("To continue press 1");
		System.out.println("or press 0 to go back");
		input = kb.nextInt();
		if(input == 0){
			
		}
		else if(input ==1){
			String first;
			String last;
			int numberOfBookings;
			
			System.out.println("What is your first and last name?");
			System.out.println("first:");
			first = kb.next();
			System.out.println("last:");
			last = kb.next();
			
			System.out.println("How many seats would you like?");
			numberOfBookings = kb.nextInt();
			event.CreateBookings(first, last, numberOfBookings);
		}

	}
	
	public static void main(String[] args) { 
		//testSetup();
		Event.loadAll();
		mainMenu();
		
	}
}
